<template>
  <div class="my_invoice_select">
    <van-sticky>
      <van-nav-bar title="发票抬头" left-arrow @click-left="back" right-text="新增" @click-right="addInvoice" />
    </van-sticky>
    <div class="list">
      <van-radio-group v-model="form.invoiceId" icon-size="0.28rem">
        <div class="item row-between-center  van-hairline--bottom" v-for="(item,index) in dataList" :key="index">
          <van-radio :name="item.id"></van-radio>
          <div class="content">
            <h4 class="name">{{item.company}}</h4>
            <p class="number">税号：{{item.taxNumber}}</p>
          </div>
          <van-icon name="edit" icon-size="0.28rem" @click="editInvoice(item)" />
        </div>
      </van-radio-group>
    </div>
    <div class="btn" @click="subInvoice">确认开票</div>
  </div>
</template>

<script>
import api from "api/api"
export default {
  data () {
    return {
      chosenAddressId: '1',
      dataList: [],
      form: {
        orderId: this.$route.params.id,
        invoiceId: ''
      }
    }
  },
  created () {
	  console.log('ss',this.$route.params.id)
	  // return;
    this.getList()
  },
  methods: {
    getList () {
      api.riser().then(res => {
        this.dataList = res.data
		console.log(this.dataList)
      })
    },
    addInvoice () {
      this.$router.push('/invoice/add')
    },
    editInvoice (item) {
      this.$router.push(`/invoice/edit/${item.id}`)
    },
    subInvoice () {
		console.log(this.form)
		// return;
      if (!this.form.invoiceId) {
        this.$toast('请选择发票')
        return
      }
      api.orderInvoice({
        data: this.form
      }).then(res => {
        this.$toast('提交成功')
        this.back()
      })
    },
    back () {
      window.history.go(-1)
    }
  }
}
</script>

<style lang="scss">
.my_invoice_select {
  min-height: 100vh;
  // background-color: #f5f5f5;
  text-align: left;
  .list {
    .item {
      padding: 0.3rem;
      background-color: #fff;
      .van-icon-edit {
        font-size: 0.36rem;
      }
      .content {
        padding: 0.1rem 0 0.1rem 0.3rem;
        flex: auto;
        .name {
          font-size: 0.32rem;
        }
        .number {
          font-size: 0.27rem;
          color: #999;
          margin: 0.23rem 0 0 0;
        }
        .price {
          font-size: 0.27rem;
          color: #ff344c;
        }
      }
    }
  }
  .mb_18 {
    margin-bottom: 0.18rem;
  }
  .mb_105 {
    margin-bottom: 1.05rem;
  }
  .btn {
    width: 6.9rem;
    line-height: 0.76rem;
    background: linear-gradient(
      96deg,
      rgba(72, 143, 240, 1),
      rgba(51, 130, 239, 1)
    );
    border-radius: 0.38rem;
    font-size: 0.36rem;
    color: #fff;
    margin: 0.9rem 0 0 0.3rem;
    text-align: center;
  }
}
</style>